package com.kehutong.material.entity;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import com.kehutong.common.entity.ITree;
import org.coraframework.bean.valid.CheckField;
import org.coraframework.orm.Entity;
import org.coraframework.orm.annotation.Column;
import org.coraframework.orm.annotation.Table;

import com.kehutong.material.enums.MaterialType;
import org.coraframework.orm.annotation.UnSave;

@Table(value="t_material", comment="素材", multi=true)
public class Material extends Entity implements ITree<Material> {

	private static final long serialVersionUID = 6827743560493446482L;

	protected Material(String id) {
		super(id);
	}

	@CheckField("上级编号不能为空")
	@Column(comment="上级编号")
	private String pid;

	@CheckField("素材名称不能为空")
	@Column(length=256, comment="素材名称")
	private String name;
	
	@Column(length=127, comment="描述")
	private String descrition;

	@Column(dbType = "TEXT", comment="内容；为图文素材存储html字符串", length = 65535)
	private String content;
	
	@Column(comment="占用内存")
	private long memory;
	
	@Column(comment="素材类型")
	private MaterialType type;
	
	@Column(comment="文件编号")
	private String fileId;

	@Column(comment="文件格式")
	private String fileType;

	@Column(length=255, comment="文件编号")
	private String shareUrl;

	@Column(length=100, comment="素材id")
	private String media_id;
	
	@Column(comment="是否文件夹")
	private boolean isFolder;
	
	@Column(comment="过期时间")
	private LocalDateTime expiredTime;
	
	@Column(comment="逻辑删除")
	private boolean deleted;

	@UnSave
	private List<Material> childList;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescrition() {
		return descrition;
	}

	public void setDescrition(String descrition) {
		this.descrition = descrition;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public long getMemory() {
		return memory;
	}

	public void setMemory(long memory) {
		this.memory = memory;
	}

	public MaterialType getType() {
		return type;
	}

	public void setType(MaterialType type) {
		this.type = type;
	}

	public String getFileType() {
		return fileType;
	}

	public void setFileType(String fileType) {
		this.fileType = fileType;
	}

	public String getFileId() {
		return fileId;
	}

	public void setFileId(String fileId) {
		this.fileId = fileId;
	}
	
	public String getShareUrl() {
		return shareUrl;
	}

	public void setShareUrl(String shareUrl) {
		this.shareUrl = shareUrl;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public String getMedia_id() {
		return media_id;
	}

	public void setMedia_id(String media_id) {
		this.media_id = media_id;
	}

	public LocalDateTime getExpiredTime() {
		return expiredTime;
	}

	public void setExpiredTime(LocalDateTime expiredTime) {
		this.expiredTime = expiredTime;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public boolean isFolder() {
		return isFolder;
	}

	public void setFolder(boolean isFolder) {
		this.isFolder = isFolder;
	}

	public void setIsFolder(boolean isFolder) {
		this.isFolder = isFolder;
	}


	public List<Material> getChildList() {
		return childList;
	}

	public void setChildList(List<Material> childList) {
		this.childList = childList;
	}

	public void addChild(Material material) {
		if (childList == null) {
			childList = new ArrayList<>();
		}
		childList.add(material);
	}
}
